from django.db import models
from datetime import datetime

# Create your models here.


class Merchants(models.Model):

    SETSSA = (
        (1, '商店申请中'),
        (2, '暂停营业'),
        (3, '商店休息'),
        (4, '开业状态u')
    )
    name = models.CharField(max_length=100, verbose_name='商家的姓名')
    nickname = models.CharField(max_length=100, verbose_name='商家的企业')
    img = models.CharField(max_length=520, verbose_name='图片')
    store = models.CharField(max_length=100, verbose_name='商店的描述')
    store_sete = models.SmallIntegerField(default=1, choices=SETSSA, verbose_name='商家状态')
    business_hours = models.DateTimeField(default=datetime.now, verbose_name='营业时间')
    business_close = models.DateTimeField(default=datetime.now, verbose_name='营业结束时间')
    sending_fee = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='起送费', null=True, blank=True)
    registr_time = models.DateTimeField(default=datetime.now(), verbose_name='创建时间')
    # table_id = models.ForeignKey(Table, on_delete=models.CASCADE)
    # merchants_users = models.ForeignKey(User, on_delete=models.CASCADE)

    class Meta:
        db_table = 'merchants'
        verbose_name_plural = '商家'

    def __str__(self):
        return self.name


class Application(models.Model):
    APPLICAT = (
        (1, '同意申请'),
        (2, '拒绝申请'),
    )
    stutsa = models.SmallIntegerField(default=1, choices=APPLICAT, verbose_name='申请状态')
    moadfs = models.ForeignKey(Merchants, on_delete=models.SET_NULL, blank=None, null=True)

    class Meta:
        db_table = 'applications'
        verbose_name_plural = '申请状态表'

    def __str__(self):
        return self.stutsa


class User(models.Model):

    GENDER = (
        (1, '男'),
        (2, '女')
    )
    LOGIN_STATUS = (
        (1, '禁止登录'),
        (2, '正常登录')
    )
    username = models.CharField(max_length=30, verbose_name='用户昵称')
    img = models.CharField(max_length=255, verbose_name='头像')
    name = models.CharField(max_length=12, verbose_name='姓名', unique=True, blank=None, null=True)
    account = models.CharField(max_length=30, verbose_name='账号',unique=True, blank=None, null=True)
    password = models.CharField(max_length=200, verbose_name='密码')
    mobile = models.CharField(max_length=128, verbose_name='手机号')
    gender = models.SmallIntegerField(default=1, choices=GENDER, verbose_name='性别')
    login_status = models.SmallIntegerField(default=1, choices=LOGIN_STATUS, verbose_name='登录状态')
    birthday = models.DateTimeField(default=datetime.now(), verbose_name='生日')
    registration_time = models.DateTimeField(default=datetime.now(), verbose_name='创建时间')
    card = models.CharField(max_length=128, verbose_name='身份证')
    describe = models.CharField(max_length=128, verbose_name='描述')
    login_time = models.DateTimeField(default=datetime.now(), verbose_name="陆时间")
    employees = models.BooleanField(default=False, verbose_name='员工权限')
    merchan = models.ForeignKey(Merchants, on_delete=models.SET_NULL, blank=None, null=True)
    rider = models.BooleanField(default=False, verbose_name='骑手开关')

    class Meta:
        db_table = 'user'
        verbose_name_plural = '用户名'

    def __str__(self):
        return self.username







